<template>
	<view class="tab-control">
		<view v-for="(item, index) in titles" :key="index" class="tab-control-item"
			:class="{ active: index === currentIndex }" @click="itemClick(index)">
			<span class="span">{{ item }}</span>
		</view>
	</view>
</template>

<script>
	export default {
		name: "TabControl",
		props: {
			titles: {
				type: Array,
				default () {
					return [];
				},
			},
		},
		data() {
			return {
				currentIndex: 0,
			};
		},
		methods: {
			itemClick(index) {
				this.currentIndex = index;
				this.$emit("tabClick", index);
			},
		},
	};
</script>
<style lang="scss" scoped>
	.tab-control {
		display: flex;
		text-align: center;
		font-size: 1rem;
		line-height: 90rpx;
		height: 90rpx;
		width: 100%;
		background-color: white;
		z-index: 2;

		.tab-control-item {
			flex: 1;
		}

		.active .span {
			border-bottom: 6rpx solid red;
		}
	}
</style>
